package com.example.dao;

import com.example.model.domain.Article;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface ArticleMapper {
    //根据id查询文章内容
    @Select("Select * from t_article where id=#{id}")
    Article selectArticleWithId(Integer id);
    //发布文章同时用options注释获取自动生成的id
    @Insert("insert into t_article(title,created,modified,tags,categories,allow_comment,thumbnail,content)"+"values(#{title},#{created},#{modified},#{tags},#{categories},"+"#{allowComment},#{thumbnail},#{content})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    Integer publishArticle(Article article);
    //分页查询
    @Select("select * from t_article order by id desc")
    List<Article> selectArticlePage();
    //通过id删除文章
    @Delete("delete from t_article where id=#{id}")
    void deleteArticleWithId(int id);
    //统计文章数量
    @Select("select count(1) from t_article")
    Integer countArticle();
    Integer updateArticleWithId(Article article);
}